//
//  WeaponView.m
//  SpaceStorm
//
//  Created by 祥 雍 on 13-4-26.
//  Copyright (c) 2013年 __MyCompanyName__. All rights reserved.
//

#import "WeaponView.h"


#pragma mark -
#pragma mark WeaponViewBase,武器视图的基类
@implementation WeaponViewBase

+(id) viewWithModelId:(int) modelId
{
    return [[[self alloc] initWithModelId:modelId] autorelease]; 
}

-(id) initWithModelId:(int) modelId
{
    self = [super init]; 
	
	if (self!= nil) 
    {
        _modelId = modelId;
        _standbyBg = [CCSprite spriteWithSpriteFrameName:[NSString stringWithFormat:@"weapon%d_0.png", modelId]];
        [self addChild:_standbyBg];
    }
    
    return self;
}

- (void) dealloc
{	
	// don't forget to call "super dealloc"
	[super dealloc];
}

@end

#pragma mark -
#pragma mark AutomaticGunView, 机关炮的视图类
@implementation AutomaticGunView
@synthesize isPlayingAction = _isPlayingAction;

-(id) initWithModelId:(int) modelId
{
    self = [super initWithModelId:modelId]; 
	
	if (self!= nil) 
    {
        _isPlayingAction = NO;
    }
    
    return self;
}

/**
	播放开火动画及闪光特效
 */
-(void) playFireAction
{
    //播放机枪的转动动画
    NSMutableArray *weaponAnimFrames = [NSMutableArray array];
    for(int i = 0; i < 2; i++) 
    {
        [weaponAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
                                     [NSString stringWithFormat:@"weapon%d_%d.png", _modelId, i]]];
    }
    
    CCAnimation *weaponAnim = [CCAnimation animationWithFrames:weaponAnimFrames delay:0.08f];
    
    CCAnimate* animate = [CCAnimate actionWithAnimation:weaponAnim];
    CCRepeatForever* repeat = [CCRepeatForever actionWithAction:animate];
    [repeat setTag:881];
    [_standbyBg runAction:repeat];
    
    //播放枪口的闪光动画
//    NSMutableArray *weaponEffectAnimFrames = [NSMutableArray array];
//    for(int i = 0; i < 1; i++) 
//    {
//        [weaponEffectAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
//                                     [NSString stringWithFormat:@"effect%d.png", _modelId]]];
//    }
//    
//    CCAnimation *weaponEffectAnim = [CCAnimation animationWithFrames:weaponEffectAnimFrames delay:0.1f];
//    
//    CCAnimate* animateEffcet = [CCAnimate actionWithAnimation:weaponEffectAnim];
//    CCRepeatForever* repeatEffect = [CCRepeatForever actionWithAction:animate];
//
//    [repeat setTag:882];
//    [_standbyBg runAction:repeatEffect];
    
    
    CCBlink* blink = [CCBlink actionWithDuration:0.16 blinks:1];
    CCSprite* _effectBg = [CCSprite spriteWithSpriteFrameName:[NSString stringWithFormat:@"weapon%d_0.png", _modelId]];
    [_standbyBg addChild:_effectBg];
    [_effectBg setTag:883];
    [_effectBg runAction:blink];
    
    //改变状态值
    _isPlayingAction = YES;
}

/**
	移除开火动画及特效
 */
-(void) stopFireAction
{
    //移除机枪转动动画
    [self stopActionByTag:881];
    
    //移除闪光动画
//    [self stopActionByTag:882];
    
    [self removeChildByTag:883 cleanup:YES];
    //更改状态值
    _isPlayingAction = NO;
}

@end

#pragma mark -
#pragma mark EnergyGunView, 动能炮的视图类
@implementation EnergyGunView


@end

#pragma mark -
#pragma mark MissileGunView, 导弹的视图类
@implementation MissileGunView


@end

#pragma mark -
#pragma mark LaserGunView, 激光炮的视图
@implementation LaserGunView


@end

